/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import modelo.Caixa;
import util.textUtil;

/**
 *
 * @author jean
 */
public class Resumo extends javax.swing.JDialog {

    /**
     * Creates new form Resumo
     */
    public Resumo(Caixa c1, Caixa c2, Caixa c3, Caixa c4) {
        super(new javax.swing.JFrame(), true);
        initComponents();
        textResumo.setEnabled(false);

        gravaResultados(c1, c2, c3, c4);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btFechar = new javax.swing.JButton();
        btGerarTxt = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        textResumo = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        btFechar.setText("Fechar");
        btFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btFecharActionPerformed(evt);
            }
        });

        btGerarTxt.setText("Gerar Txt");
        btGerarTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btGerarTxtActionPerformed(evt);
            }
        });

        textResumo.setColumns(20);
        textResumo.setRows(5);
        textResumo.setDisabledTextColor(new java.awt.Color(1, 1, 1));
        jScrollPane1.setViewportView(textResumo);

        jLabel1.setText("Resultados Finais");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(btGerarTxt)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btFechar))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(136, 136, 136)
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btFechar)
                    .addComponent(btGerarTxt))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btGerarTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btGerarTxtActionPerformed
        final JFileChooser fc = new JFileChooser();

        UIManager.put("FileChooser.openDialogTitleText", "Salvar em");
        UIManager.put("FileChooser.lookInLabelText", "Consultar em");
        UIManager.put("FileChooser.openButtonText", "Salvar");
        UIManager.put("FileChooser.cancelButtonText", "Cancelar");
        UIManager.put("FileChooser.fileNameLabelText", "Nome do Arquivo");
        UIManager.put("FileChooser.filesOfTypeLabelText", "Tipo de Arquivo");
        UIManager.put("FileChooser.openButtonToolTipText", "Abrir o Arquivo Selecionado");
        UIManager.put("FileChooser.cancelButtonToolTipText", "Cancelar");
        UIManager.put("FileChooser.fileNameHeaderText", "Nome");
        UIManager.put("FileChooser.upFolderToolTipText", "Subir um Nível");
        UIManager.put("FileChooser.homeFolderToolTipText", "Área de Trabalho");
        UIManager.put("FileChooser.newFolderToolTipText", "Criar Nova Pasta");
        UIManager.put("FileChooser.listViewButtonToolTipText", "Lista");
        UIManager.put("FileChooser.newFolderButtonText", "Criar Nova Pasta");
        UIManager.put("FileChooser.renameFileButtonText", "Renomear");
        UIManager.put("FileChooser.deleteFileButtonText", "Deletar");
        UIManager.put("FileChooser.filterLabelText", "Tipo");
        UIManager.put("FileChooser.detailsViewButtonToolTipText", "Detalhes");
        UIManager.put("FileChooser.fileSizeHeaderText", "Tamanho");
        UIManager.put("FileChooser.fileDateHeaderText", "Data de Modificação");
        UIManager.put("FileChooser.acceptAllFileFilterText", "Todos os Arquivos");

        SwingUtilities.updateComponentTreeUI(fc);

        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            String path = fc.getSelectedFile().getPath();
            try {
                textUtil.salvar(path, textResumo.getText(), false);

                JOptionPane.showMessageDialog(null, "Gerado com Sucesso em: " + path, "Gerado com sucesso.", JOptionPane.INFORMATION_MESSAGE);
            } catch (IOException ex) {
                Logger.getLogger(Simulacao.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_btGerarTxtActionPerformed

    private void btFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFecharActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_btFecharActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btFechar;
    private javax.swing.JButton btGerarTxt;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea textResumo;
    // End of variables declaration//GEN-END:variables

    private void gravaResultados(Caixa c1, Caixa c2, Caixa c3, Caixa c4) {

        textResumo.append("Nome: " + c1.getEtiqueta());
        textResumo.append("\nNúmero de Clientes Atendidos: " + c1.getNumClientesAtendidos());
        textResumo.append("\nClientes Restantes na Fila: " + c1.getNumClientesRestantes());
        textResumo.append("\nTamanho Máximo da Fila: " + c1.getTamanhoMax());
        textResumo.append("\nTamanho Mínimo da Fila: " + c1.getTamanhoMin());
        textResumo.append("\nNúmero de Vezes Vazio: " + c1.getNumVezesVazia());
        textResumo.append("\nTempo Médio de Espera: " + c1.getTempoMedioEspera() + " minuto(s)");

        textResumo.append("\n\nNome: " + c2.getEtiqueta());
        textResumo.append("\nNúmero de Clientes Atendidos: " + c2.getNumClientesAtendidos());
        textResumo.append("\nClientes Restantes na Fila: " + c2.getNumClientesRestantes());
        textResumo.append("\nTamanho Máximo da Fila: " + c2.getTamanhoMax());
        textResumo.append("\nTamanho Mínimo da Fila: " + c2.getTamanhoMin());
        textResumo.append("\nNúmero de Vezes Vazio: " + c2.getNumVezesVazia());
        textResumo.append("\nTempo Médio de Espera: " + c2.getTempoMedioEspera() + " minuto(s)");

        textResumo.append("\n\nNome: " + c3.getEtiqueta());
        textResumo.append("\nNúmero de Clientes Atendidos: " + c3.getNumClientesAtendidos());
        textResumo.append("\nClientes Restantes na Fila: " + c3.getNumClientesRestantes());
        textResumo.append("\nTamanho Máximo da Fila: " + c3.getTamanhoMax());
        textResumo.append("\nTamanho Mínimo da Fila: " + c3.getTamanhoMin());
        textResumo.append("\nNúmero de Vezes Vazio: " + c3.getNumVezesVazia());
        textResumo.append("\nTempo Médio de Espera: " + c3.getTempoMedioEspera() + " minuto(s)");

        textResumo.append("\n\nNome: " + c4.getEtiqueta());
        textResumo.append("\nNúmero de Clientes Atendidos: " + c4.getNumClientesAtendidos());
        textResumo.append("\nClientes Restantes na Fila: " + c4.getNumClientesRestantes());
        textResumo.append("\nTamanho Máximo da Fila: " + c4.getTamanhoMax());
        textResumo.append("\nTamanho Mínimo da Fila: " + c4.getTamanhoMin());
        textResumo.append("\nNúmero de Vezes Vazio: " + c4.getNumVezesVazia());
        textResumo.append("\nTempo Médio de Espera: " + c4.getTempoMedioEspera() + " minuto(s)");

        textResumo.setCaretPosition(0);
    }
}